﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ershou.BLL;
using System.Data.SqlClient;
using System.IO;
using System.Threading;

public partial class grxx2 : System.Web.UI.Page
{
    public yh yh1 = new yh();
    public int n = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["CustomerId"] == null)
        {
            Response.Redirect("~/dl.aspx");
        }
        Label4.Text = "";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        
        string img = Session["CustomerId"] + Path.GetExtension(FileUpload1.FileName);
        if (FileUpload1.PostedFile.ContentLength != 0)
        {
            string filePath = Server.MapPath("~/") + "Image\\yh\\"+ Session["CustomerId"]+ Path.GetExtension(FileUpload1.FileName);
            File.Delete(filePath);
            FileUpload1.PostedFile.SaveAs(filePath);
        }
        if(FileUpload1.PostedFile.ContentLength == 0)
        {
            img = yh1.select7(Convert.ToInt32(Session["CustomerId"].ToString()));
        }
        string d = TextBox4.Text.Trim() + "-" + TextBox5.Text.Trim() + "-" + TextBox6.Text.Trim();
        if (TextBox4.Text=="" || TextBox5.Text == "" || TextBox6.Text == "")
        {
            yh1.Update2((int)Session["CustomerId"], TextBox1.Text.Trim(), TextBox2.Text.Trim(),
            TextBox7.Text.Trim(), TextBox9.Text.Trim(),img);
        }
        else
        {
            yh1.Update1((int)Session["CustomerId"], TextBox1.Text.Trim(), TextBox2.Text.Trim(), d,
            TextBox7.Text.Trim(), TextBox9.Text.Trim(), img);
        }
        Session["Customername"] = TextBox1.Text.Trim();
        Response.Redirect("~/Default.aspx");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string id = Session["CustomerId"].ToString();
        int i = int.Parse(id);
        TextBox1.Text = yh1.select1(i);
        TextBox2.Text = yh1.select2(i);
        string time = yh1.select3(i);
        if (time.Length > 8)
        {
            TextBox4.Text = DateTime.Parse(time).Year.ToString();
            TextBox5.Text = DateTime.Parse(time).Month.ToString();
            TextBox6.Text = DateTime.Parse(time).Day.ToString();
        }
        TextBox7.Text = yh1.select4(i);
        TextBox8.Text = yh1.select5(i);
        TextBox9.Text = yh1.select6(i);
        Image1.ImageUrl = "~/Image/yh/" + yh1.select7(i);
    }
}